<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>地址查询列表</title>
    <link rel="stylesheet" type="text/css" href="/secondhand/css/query.css"/>
    <script type="text/javascript" src="/secondhand/js/jquery-3.2.1.js"></script>
    <script type="text/javascript">
        $(function () {
            var param = new URLSearchParams(window.location.search);
            var pageNo = param.get("pageNo");
            var likeValue = param.get("likeValue");
            selectByPage(pageNo, likeValue);
            //点击查询按钮
            $("#selectAddressByLikeValue").click(function () {
                var likevalueaddress = $.trim($("#likevalueaddress").val());
                selectByPage(1, likevalueaddress);
            })
            //添加地址成功
            var isSuccess = param.get("addSuccess");
            if (isSuccess != null && isSuccess == 1) {
                alert("添加地址成功！");
            }
            //删除地址成功
            var isSuccess1 = param.get("deleteSuccess");
            if (isSuccess1 != null && isSuccess1 == 1) {
                alert("删除地址成功！");
            }
            //修改地址成功
            var isSuccess2 = param.get("updateSuccess");
            if (isSuccess2 != null && isSuccess2 == 1) {
                alert("修改地址成功！");
            }
        })

        //分页查询
        function selectByPage(pageNo, likevalue) {
            var url = "/secondhand/selectByPage.address";
            var paramObj = {
                "pageNo": pageNo,
                "likeValue": likevalue
            };
            $.post(url, paramObj, function (data) {
                $("#tbodyList").empty();
                var jsonObj = JSON.parse(data);
                var recordList = jsonObj.recordList;
                for (var i = 0; i < recordList.length; i++) {
                    $("<tr><td>" + recordList[i].addressid + "</td><td>"
                        + recordList[i].userfullname + "</td><td>"
                        + recordList[i].address + "</td><td>"
                        + recordList[i].phone +
                        "</td><td><a href='/secondhand/toUpdate.address?addressid=" + recordList[i].addressid + "'>编辑</a></td>" +
                        "<td><a href='/secondhand/deleteById.address?addressid=" + recordList[i].addressid + "' onclick='confirmDelete(this)'>删除</a></td></tr>").appendTo($("#tbodyList"));
                }
                $("#likevalueaddress").val(jsonObj.likeValue);//回填查询条件
                $("#recordCount").text(jsonObj.recordCount);//总记录数
                $("#totalPages").text(jsonObj.totalPages);//总页数
                $("#pageNo").text(jsonObj.pageNo);//当前页
                //首页
                $("#firstPage").prop("href", "/secondhand/toList.address?pageNo=1&likeValue=" + jsonObj.likeValue);
                //上一页
                if (jsonObj.pageNo != 1)
                    $("#prevPage").prop("href", "/secondhand/toList.address?pageNo=" + (jsonObj.pageNo - 1) + "&likeValue=" + jsonObj.likeValue);
                //下一页
                if (jsonObj.pageNo != jsonObj.totalPages)
                    $("#nextPage").prop("href", "/secondhand/toList.address?pageNo=" + (jsonObj.pageNo + 1) + "&likeValue=" + jsonObj.likeValue);
                //尾页
                $("#tailPage").prop("href", "/secondhand/toList.address?pageNo=" + jsonObj.totalPages + "&likeValue=" + jsonObj.likeValue);
            })
        }

        //删除确认
        function confirmDelete(obj) {
            var categoryName = $(obj).parent().parent().find("td").eq(1).text();
            if (!confirm("确定要删除" + categoryName + "吗？")) {
                event.preventDefault();
            }
        }

    </script>
</head>
<body>
<div id="top">·当前位置： 系统管理 -- 查看地址</div>
<div id="contexttop">
    <table id="tab" border="1" style="width: 80%;">
        <tr>
            <td colspan="7" height="50px">
                <form method="post">
                    <input type="text" id="likevalueaddress" title="地址，手机号" placeholder="地址，手机号"/>
                    <input type="button" value="查询" id="selectAddressByLikeValue"/>
                </form>
            </td>
        </tr>
        <tr bgcolor="#cccccc">
            <th>地址ID</th>
            <th>用户昵称</th>
            <th width="300px">地址</th>
            <th>手机号</th>
            <th colspan=2>操作</th>
        </tr>
        <tbody id="tbodyList"></tbody>
    </table>
</div>
<div align="center" id="contextbotton">
    &nbsp;总记录数<span id="recordCount"></span>条&nbsp;共<span id="totalPages"></span>页 &nbsp;
    <a id="firstPage" href="#">首页</a>&nbsp;
    <a id="prevPage" href="#">上一页</a> &nbsp;
    <a id="nextPage" href="#">下一页</a> &nbsp;
    <a id="tailPage" href="#">尾页</a>&nbsp;
    &nbsp;第<span id="pageNo"></span>页
</div>
</body>
</html>